<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>作用域</title>
</head>

<body>
  <script>
    function fn(a,c){
      console.log(a) // function a(){}
      var a = 123;
      console.log(a); // 123
      console.log(c); // function c(){}
      function a(){}
      if(false) var d = 678;
      console.log(d); // undefined
      console.log(b); // undefined
      var b = function (){}  // 这里是是函数表达式不是函数声明
      console.log(b); //function (){}
      function c(){}
      console.log(c); // function c(){}
    }
    fn(1,2)
    /* 
      * 创建AO对象
      * 找形参和变量声明，将变量和形参名当做AO对象的属性名，值为undefined
      * 实参形参相统一
      * 在函数体里面找函数声明，值赋予函数体
    */
    /* AO={
       a:undefined, // 1  function a(){}
       c:undefined, // 2  function c(){}
       d:undefined,
       b:undefined
   } */
  </script>
  <script>
    /* var global;
    function a(){
      function b(){
        var bb = 234;
        aa = 0;
      }
      var aa = 123;
      b()
    }
    a() */

    function a(){
      var aa = 123;
      function b(){
        var bb = 234;
        console.log(aa)
      }
      return b;
    }
    var res = a();
    res()
  </script>
</body>

</html>